﻿namespace CodeParser.Tokens
{
    public class SingleCharRange
        : TokenParser
    {

        public SingleCharRange(TokenType type, char min, char max)
            : base(type)
        {
            Min = min;
            Max = max;
        }

        public override Token GetTokenAt(string source, int index)
        {
            var i = index;
            var sourceLength = source.Length;
            while (i < sourceLength)
            {
                var currentChar = source[i];
                if (currentChar < Min || currentChar > Max || i == sourceLength)
                {
                    return i > index
                               ? new Token() { Index = index, Type = Type.Value, Value = source.Substring(index, i - index) }
                               : null;
                }
                i++;
            }
            return null;
        }

        public char Min, Max;

    }
}
